﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace GodPl.WorldState
{
    public class Weather
    {

        private World world;

        public Weather(World world)
        {
            this.world = world;
        }

        /// <summary>
        /// Returns whether it's currently raining
        /// </summary>
        public bool IsRaining
        {
            get { return isRaining; }
        }

        /// <summary>
        /// Returns how long the current rain has been going on, in GameTime
        /// </summary>
        public TimeSpan CurrentRainDuration
        {
            get { return currentRainDuration; }
        }

        bool isRaining = false;
        bool rainIndefinitely = false;
        TimeSpan rainDurationRemaining = TimeSpan.Zero;
        TimeSpan currentRainDuration = TimeSpan.Zero;

        public void StartRaining(TimeSpan duration)
        {
            rainDurationRemaining = duration;
            isRaining = true;
            rainIndefinitely = false;
        }

        public void StartRaining()
        {
            isRaining = true;
            rainIndefinitely = true;
        }

        public void StopRaining()
        {
            isRaining = false;
            rainIndefinitely = false;
            rainDurationRemaining = TimeSpan.Zero;
        }

        public void Update(GameTime gameTime)
        {
            rainDurationRemaining -= gameTime.ElapsedGameTime;
            currentRainDuration += gameTime.ElapsedGameTime;

            if (rainDurationRemaining == TimeSpan.Zero && (!rainIndefinitely))
            {
                StopRaining();
            }
        }

        /// <summary>
        /// The current temperature (in degrees Celsius, in case it matters)
        /// </summary>
        public float Temperature
        {
            get { return temperature; }
            set { temperature = value; }
        }

        float temperature = 25.0f;
    }
}
